import { createRouter, createWebHistory } from 'vue-router'
import DashboardView from '../views/DashboardView.vue'
import DataEntryView from '../views/DataEntryView.vue'
import DataBoardView from '../views/DataBoardView.vue'
import DataSubmitView from '../views/DataSubmitView.vue'
import UserInfoView from '../views/UserInfoView.vue'
import LoginView from '../views/LoginView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    {
      path: '/dashboard',
      name: 'dashboard',
      component: DashboardView,
      meta: { title: '仪表盘' }
    },
    {
      path: '/data-entry',
      name: 'data-entry',
      component: DataEntryView,
      meta: { title: '数据录入' }
    },
    {
      path: '/data-board',
      name: 'data-board',
      component: DataBoardView,
      meta: { title: '数据看板' }
    },
    {
      path: '/data-submit',
      name: 'data-submit',
      component: DataSubmitView,
      meta: { title: '数据提交' }
    },
    {
      path: '/user-info',
      name: 'user-info',
      component: UserInfoView,
      meta: { title: '信息维护' }
    },
    {
      path: '/login',
      name: 'login',
      component: LoginView,
      meta: { hideNavbar: true, title: '登录' }
    },
    // 添加默认重定向到登录页面
    {
      path: '/:pathMatch(.*)*',
      redirect: '/login'
    }
    // 在此处可以添加体测系统的其他路由
  ]
})

// 全局前置守卫，用于控制登录状态
router.beforeEach((to, from, next) => {
  // 设置页面标题
  document.title = to.meta.title ? `${to.meta.title} - 体测数据上报系统` : '体测数据上报系统'
  
  // 这里可以添加登录验证逻辑
  // 例如检查是否有登录令牌等
  next()
})

export default router
